package com.lhx.crud.service;

import com.lhx.crud.bean.Employee;
import com.lhx.crud.bean.EmployeeExample;
import com.lhx.crud.dao.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
public class EmployeeService {

    //注入dao
    @Autowired
    EmployeeMapper employeeMapper;

    //得到员工所有数据
    public List<Employee> getAll() {

        return employeeMapper.selectByExampleWithDept();
    }
    //保存员工信息
    public void  save_Emp (Employee employee){
        employeeMapper.insertSelective(employee);
    }

    //校验员工信息
    public boolean check( String emp_name) {

        EmployeeExample example = new EmployeeExample();
        //创建Criteria
        EmployeeExample.Criteria criteria =  example.createCriteria();
        //
        criteria.andEmp_nameEqualTo(emp_name);

        //
       long count= employeeMapper.countByExample(example);
        return count==0 ;
    }

    //删除 单个员工信息
    public  void del_Emp(Integer id){
        employeeMapper.deleteByPrimaryKey(id);


    }

    //id查询信息
    public Employee getEmp(Integer id) {

       Employee employee =employeeMapper.selectByPrimaryKey(id);
            return  employee;


    }

    //批量删除
    public void del_Emps(List<Integer> ids) {
        EmployeeExample employeeExample = new EmployeeExample();
        //会序列化id
       EmployeeExample.Criteria criteria = employeeExample.createCriteria();
        criteria.andEmp_idIn(ids);
       employeeMapper.deleteByExample(employeeExample);


    }
}
